import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { RedisClientOptions } from 'redis';
import { CacheModule } from '@nestjs/cache-manager';
import redisStore from 'cache-manager-redis-store';
import { User } from './user/user.entity';
import { UserService } from './user/user.service';
import { UserController } from './user/user.controller';
import { loginService } from './modules/login/login.service';
import { loginController } from './modules/login/login.controller';
import { UploadController } from './upload/upload.controller';
import { UploadService } from './upload/upload.service';
import { JwtModule } from '@nestjs/jwt';
import { AuthService } from './jwt/auth.service';
import { MulterModule } from '@nestjs/platform-express';
import { diskStorage } from 'multer';
import { extname, join } from 'path';
import { UploadModule } from './upload/upload.module';
import { ServeStaticModule } from '@nestjs/serve-static';
@Module({
  imports: [
    TypeOrmModule.forRoot({
      type: 'mysql',
      host: 'localhost',
      port: 3306,
      username: 'root',
      password: '2212422273',
      database: 'nest-admin',
      entities: [User],
      synchronize: true,
    }),
    CacheModule.register<RedisClientOptions>({
      store: redisStore,
      host: 'localhost',
      port: 6379,
      password: '', // 如果有密码
      db: 0, // 数据库索引
      ttl: 600, // 默认过期时间（秒）
    } as any),
    ServeStaticModule.forRoot({
      rootPath: join(__dirname, '..', 'uploads'),
      serveRoot: '/files', // 访问路径前缀
      serveStaticOptions: {
        index: false, // 禁用目录索引
        dotfiles: 'deny', // 拒绝访问点文件
        cacheControl: true, // 启用缓存控制
        maxAge: 86400000, // 缓存一天
      },
    }),
    TypeOrmModule.forFeature([User]),
    JwtModule.register({
      secret: 'wohahah', // 替换为你的密钥
      signOptions: { expiresIn: '2h' }, // 设置 Token 过期时间
    }),
  ],
  exports: [JwtModule],
  controllers: [UserController, loginController, UploadController],
  providers: [UserService, loginService, AuthService, UploadService],
})
export class AppModule {}
